package com.b511.swpu.cementbackend.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CollectionUtils {
    public static List<Collection<String>> splitCollection(Collection<String>values, int size) {
        List<Collection<String>> result = new ArrayList<Collection<String>>();
        if(values.size() <= size ){
            result.add(values);
        }else{
            int count =0;
            Collection<String> subCollection= null;
            for(String s: values){
                if(subCollection == null){
                    subCollection = new ArrayList<String>();
                    result.add(subCollection);
                }
                subCollection.add(s);
                count++;
                if(count == size){
                    count =0;
                    subCollection = null;
                }
            }
        }
        return result;
    }
}
